
const { randomString } = require('../utils/common');
const { uploadFileFromUrl, getWBFileList } = require('../utils/uploadfile');
const { logger } = require('../utils/serviceLogger');

exports.getRandomAvatar = async (req, res) => {
    const randomStr = await randomString('1,2,3', '', 16);
    const randomAvatar = 'https://api.multiavatar.com/' + randomStr + '.png';
    const url = await uploadFileFromUrl(randomStr, randomAvatar, 'random-avatar');
    return res.send(url);
}

exports.getRandomString = async (req, res) => {
    logger.info(req, {
        label: '获取随机字符串接口，请求参数为：'
    });
    const dataStr = await randomString(req.query.charType, req.query.customizeChar, req.query.length);
    logger.info(dataStr, {
        label: '获取随机字符串接口，响应参数为：'
    });
    return res.send({
        flag: 1,
        msg: 'success',
        data: dataStr,
    });
}

exports.getWBFileList = async (req, res) => {
    const res2 = await getWBFileList(req.query.path);
    return res.send({
        flag: 1,
        msg: 'success',
        data: res2
    });
}